def count_bmr(gender0, age0, height0, weight0):  #bmr计算函数
    if gender0 == "男":
        BMR = 66.473 + (13.7516 * weight0) + (5.0033 * height0) - (6.755 * age0)
    elif gender0 == "女":
        BMR = 655.0955 + (9.5634 * weight0) + (1.8496 * height0) - (4.6756 * age0)
    else:
        BMR = -1
    return BMR

def colorful_warning(w):  #字体颜色函数
    from colorama import Fore, Style
    print(Fore.RED + w)
    print(Style.RESET_ALL)
    return w

def out_put(h,i,j,k,l):  #输入报告函数
    print("你的计算报告\n"
          "性别：{}\n"
          "年龄：{}岁\n"
          "身高：{}cm\n"
          "体重：{}kg\n"
          "BMR指数：{:.2f}\n".format(h,i,j,k,l))

# def value_splt(n):
#     input_v = []
#     if n == 0:
#         g = input_v[0]
#     elif n == 1:
#         o = eval(input_v[1])
#     elif n == 2:
#         he = float(input_v[2])
#     elif n == 3:
#         we = float(input_v[3])


print("{0:*^30}".format("欢迎使用BMR(基础代谢率)计算器"))
while True:
    b_e = input("是否退出程序（y/n）：")
    if b_e == 'y':
        print("{0:*^30}".format("退出计算器"))
        break
    elif b_e == 'n':

        while b_e == 'n':
            print("请依次输入以下信息，使用空格隔开")
            a = input("性别 年龄 身高(cm) 体重(kg)：")
            input_split = a.split(" ")
            try:
                gender = input_split[0]
                age = eval(input_split[1])
                height = float(input_split[2])
                weight = float(input_split[3])
                bmr = count_bmr(gender,age,height,weight)
                if bmr != -1:
                    if bmr <= 0:
                        print(colorful_warning("输入信息有误，请重新输入你的信息"))
                        again = input("请重新输入性别 年龄 身高(cm) 体重(kg)：")
                        second_split = again.split(" ")
                        gender1 = second_split[0]
                        age1 = eval(second_split[1])
                        height1 = float(second_split[2])
                        weight1 = float(second_split[3])
                        bmr1 = count_bmr(gender1, age1, height1, weight1)
                        out_put(gender1,age1,height1,weight1,bmr1)
                        end = input("是否退出程序（y/n）")
                        if end == 'y':
                            print("{0:*^30}".format("退出计算器，感谢你的使用( •̀ ω •́ )✧"))
                            break
                    else:
                        out_put(gender,age,height,weight,bmr)
                        end = input("是否退出程序（y/n）")
                        if end == 'y':
                            print("{0:*^30}".format("退出计算器，感谢你的使用( •̀ ω •́ )✧"))
                            break
                else:
                    colorful_warning("性别格式填写错误")
                    end = input("是否退出程序（y/n）")
                    if end == 'y':
                        print("{0:*^30}".format("退出计算器，感谢你的使用"))
                        break
            except ValueError:
                colorful_warning("输入信息格式错误，请重新输入！")
            except IndexError:
                colorful_warning("输入的信息不完整，请重新输入！")
            except:
                colorful_warning("该版本计算器暂时无法支持此操作，抱歉！")
        break
    else:
        colorful_warning("继续程序请输入n，退出程序请输入y，请重新输入！")









